package com.tywj.panda.customer.usercenter.settings

import android.os.Bundle
import android.view.Gravity
import android.view.WindowManager
import com.tywj.panda.customer.common.view.dialog.BottomDialog
import com.tywj.lib.businessweak.view.IBaseView
import com.tywj.lib.core.common.extension.onClick
import com.tywj.panda.customer.usercenter.R
import kotlinx.android.synthetic.main.user_logout_dialog.*

/**
 * 退出登录对话框
 */
class TipsDialog : BottomDialog() {

    companion object {
        const val TAG = "LogoutDialog"
    }

    private var mTips = ""

    private var comFirmListener: (() -> Unit)? = null

    override fun getLayoutID(): Int = R.layout.user_logout_dialog

    override fun getGravity(): Int = Gravity.CENTER

    override fun getWidth(): Int = WindowManager.LayoutParams.WRAP_CONTENT

    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)
        tvTips.text = mTips
    }

    override fun initListener() {
        super.initListener()

        ivClose.onClick {
            dismissDialog()
        }

        btnCancel.onClick {
            dismissDialog()
        }

        btnConfirm.onClick {
            comFirmListener?.invoke()
            dismissDialog()
        }
    }

    class Builder(private val baseView: IBaseView) {

        private var mTips = ""

        private var comFirmListener: (() -> Unit)? = null

        fun setTipDetails(tips: String = ""): Builder {
            mTips = tips
            return this
        }

        fun builder(): TipsDialog {
            val dialog = TipsDialog()
            dialog.mTips = mTips
            dialog.comFirmListener = comFirmListener
            return dialog
        }

        fun setConfirmListener(listener: () -> Unit): Builder {
            comFirmListener = listener
            return this
        }

        fun show(): TipsDialog {
            val dialog = builder()
            dialog.showDialog(baseView.getFragmentManagerInstance())
            return dialog
        }
    }
}